import json


def convert_format(example):
    return {
        "messages": [
            {"role": "system", "content": "你是一名软件工程课程的AI助教"},
            {"role": "user", "content": example["question"]},
            {"role": "assistant", "content": example["answer"]},
        ]
    }


with open("../dataset/qa_pairs.json", "r") as f_in, open(
    "../dataset/converted_data.json", "w"
) as f_out:
    data = json.load(f_in)
    for item in data:
        converted = convert_format(item)
        f_out.write(json.dumps(converted, ensure_ascii=False) + "\n")
        # question = item["question"]
        # print(question)
    # for line in f_in:
    #     print(line)
    #     data = json.loads(line)
    #     converted = convert_format(data)
    #     f_out.write(json.dumps(converted, ensure_ascii=False) + "\n")
